<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24" v-if="accCode == '' ">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户号">
          <!-- <j-dict-select-tag v-model="queryParam.cusId" placeholder="请选择用户号" dictCode="mws_t_arc_customers,code,id"/> -->
          <a-input placeholder="请输入户号" class="query-group-cust" v-model="queryParam.cusId" style="width:100%"></a-input> 
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户名">
             <a-input v-model="queryParam.cusName" placeholder="请输入用户名"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="月份">
            <a-input class="query-group-cust" v-model="queryParam.readMonth_begin" placeholder="请输入最开始值"/>
            <span class="query-group-split-cust"></span>
            <a-input class="query-group-cust" v-model="queryParam.readMonth_end" placeholder="请输入最结束值"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="抄表员">
             <a-input v-model="queryParam.readerId" placeholder="请输入抄表员"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="抄表本号">
          <j-dict-select-tag v-model="queryParam.bookId" placeholder="请选择抄表本号" dictCode="mws_t_mr_books,name,id"/>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="抄表日期">
             <a-input v-model="queryParam.readTime" placeholder="请输入抄表日期"/>
            </a-form-item>
          </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator" v-if="accCode == '' ">
      <a-button type="primary" icon="notification" @click="handleWxmsgArrears">微信催缴通知</a-button> 
      <a-button type="primary" icon="notification" @click="handleSmsmsgArrears">短信催缴通知</a-button> 
      <a-button type="primary" icon="notification" @click="handleSmsmsgStopArrears">短信催缴停水通知</a-button> 
      <a-button type="primary" icon="download" @click="handleExportXls('欠费记录')">导出</a-button> 
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel" v-if="username == 'admin'">
        <a-button type="primary" icon="import" >导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
       
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
       <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <!-- <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="欠费明细" key="chgSubArrear" forceRender>
              <chg-sub-arrear-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="ellipsisText" slot-scope="text">
          <j-ellipsis :value="text" :length="textMaxLength"></j-ellipsis>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>


        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <chg-arrears-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction} from '@/api/manage'
  import ChgArrearsModal from './modules/ChgArrearsModal'
  import ChgSubArrearSubTable from './subTables/ChgSubArrearSubTable'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import '@/assets/less/TableExpand.less'

  export default {
    name: 'ChgArrearsList',
    mixins: [JeecgListMixin],
    components: {
      JEllipsis,
      ChgArrearsModal,
      ChgSubArrearSubTable,
      JDictSelectTag,
    },
    props: {
      accCode:{
        type: String,       
        default: ''
      }
    },
    data() {
      return {
        description: '欠费记录列表管理页面',
        disableMixinCreated:true,
        textMaxLength:5,
        username:'',
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '用户号',
            align: 'center',
            dataIndex: 'cusId'
          },
          {
            title: '用户名',
            align: 'center',
            dataIndex: 'cusName',
            scopedSlots: {customRender: "ellipsisText"}
          },
          {
            title: '抄表本',
            align: 'center',
            dataIndex: 'bookId_dictText'
          },
          // {
          //   title: '抄表员',
          //   align: 'center',
          //   dataIndex: 'readerId',
          // },
          // {
          //   title: '用水性质',
          //   align: 'center',
          //   dataIndex: 'natureId_dictText'
          // },
          {
            title: '月份',
            align: 'center',
            dataIndex: 'readMonth',
          },
          {
            title: '起度',
            align: 'center',
            dataIndex: 'beginScale',
          },
          {
            title: '止度',
            align: 'center',
            dataIndex: 'endScale',
          },
          // {
          //   title: '抄见水量',
          //   align: 'center',
          //   dataIndex: 'readAmount',
          // },
          // {
          //   title: '换表读数',
          //   align: 'center',
          //   dataIndex: 'replaceMeterScale',
          // },
          // {
          //   title: '换表水量',
          //   align: 'center',
          //   dataIndex: 'replaceAmount',
          // },
          // {
          //   title: '计量水量',
          //   align: 'center',
          //   dataIndex: 'measureAmount',
          // },
          
          {
            title: '计费水量',
            align: 'center',
            dataIndex: 'measureAmount',
          },
          {
            title: '水费',
            align: 'center',
            dataIndex: 'totalMoney',
          },
          {
            title:'污水费',
            align:"center",
            dataIndex: 'wuMoney'
          },
          {
            title:'垃圾费',
            align:"center",
            dataIndex: 'ljMoney'
          },
          {
            title: '杂项费',
            align: 'center',
            dataIndex: 'alienMoney',
          },

          // {
          //   title: '增值税金额',
          //   align: 'center',
          //   dataIndex: 'vatMoney',
          // },        
          {
            title: '实计金额',
            align: 'center',
            dataIndex: 'money',
          },
          {
            title: '违约金',
            align: 'center',
            dataIndex: 'penalty',
          },
          // {
          //   title: '违约天数',
          //   align: 'center',
          //   dataIndex: 'penaltyDay',
          // },
         
          // {
          //   title: '抄表日期',
          //   align: 'center',
          //   dataIndex: 'readTime',
          // },
          // {
          //   title: '水表状态',
          //   align: 'center',
          //   dataIndex: 'waterUsedType_dictText'
          // },
          // {
          //   title: '已收金额',
          //   align: 'center',
          //   dataIndex: 'recivedMoney',
          // },
          {
            title: '欠费金额',
            align: 'center',
            dataIndex: 'arrearMoney',
          },
          {
            title: '欠费水量',
            align: 'center',
            dataIndex: 'arrearAmount',
          },
          {
            title: '优惠水量',
            align: 'center',
            dataIndex: 'ajustedAmount',
          },
          {
            title: '优惠金额',
            align: 'center',
            dataIndex: 'discountMoney',
          },
          // {
          //   title: '已收水量',
          //   align: 'center',
          //   dataIndex: 'recivedAmount',
          // },
         
          // {
          //   title: '锁定水量',
          //   align: 'center',
          //   dataIndex: 'lockedAmount',
          // },
          // {
          //   title: '锁定金额',
          //   align: 'center',
          //   dataIndex: 'lockedMoney',
          // },
          // {
          //   title: '操作日期',
          //   align: 'center',
          //   dataIndex: 'operatedTime',
          // },
         
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/chg/chgArrears/list',
          msgList: '/chg/chgArrears/wxmsgArrears',
          smsmsgList: '/chg/chgArrears/smsmsgArrears',
          smsmsgStopList: '/chg/chgArrears/smsmsgStopArrears',
          delete: '/chg/chgArrears/delete',
          deleteBatch: '/chg/chgArrears/deleteBatch',
          exportXlsUrl: '/chg/chgArrears/exportXls',
          importExcelUrl: '/chg/chgArrears/importExcel',
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.username = this.userInfo.username;
      this.queryParam.cusId=this.accCode;
      if(this.accCode){
        this.loadData();
      }
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      },
      userInfo() {
        return this.$store.getters.userInfo
      } 
    },
    methods: {
      initDictConfig() {
      },
      handleWxmsgArrears(){
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.msgList, params).then((res) => {
          if (res.success) {
           this.$message.success(res.message)
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      handleSmsmsgArrears(){
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.smsmsgList, params).then((res) => {
          if (res.success) {
           this.$message.success(res.message)
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      handleSmsmsgStopArrears(){
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.smsmsgStopList, params).then((res) => {
          if (res.success) {
           this.$message.success(res.message)
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'cusId',text:'用户号',dictCode:'mws_t_arc_customers,code,id'})
        fieldList.push({type:'string',value:'cusName',text:'用户名',dictCode:''})
        fieldList.push({type:'string',value:'natureId',text:'用水性质',dictCode:'mws_t_base_natures,name,id'})
        fieldList.push({type:'string',value:'readMonth',text:'月份',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'beginScale',text:'起度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'endScale',text:'止度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'readAmount',text:'抄见水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'replaceMeterScale',text:'换表读数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'replaceAmount',text:'换表水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'measureAmount',text:'计量水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'ajustedAmount',text:'减免水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'amount',text:'计费水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalMoney',text:'合计金额(仅水费)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'vatMoney',text:'增值税金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'discountMoney',text:'优惠金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'alienMoney',text:'杂项金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'money',text:'折后金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'penalty',text:'违约金',dictCode:''})
        fieldList.push({type:'int',value:'penaltyDay',text:'违约天数',dictCode:''})
        fieldList.push({type:'string',value:'readerId',text:'抄表员',dictCode:''})
        fieldList.push({type:'string',value:'bookId',text:'抄表本号',dictCode:'mws_t_mr_books,name,id'})
        fieldList.push({type:'string',value:'readTime',text:'抄表日期',dictCode:''})
        fieldList.push({type:'string',value:'waterUsedType',text:'水表状态',dictCode:'water_used_type'})
        fieldList.push({type:'BigDecimal',value:'recivedMoney',text:'已收金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'arrearMoney',text:'欠费金额包括违约金',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'recivedAmount',text:'已收水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'arrearAmount',text:'欠费水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lockedAmount',text:'锁定水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lockedMoney',text:'锁定金额',dictCode:''})
        fieldList.push({type:'string',value:'operatedTime',text:'操作日期',dictCode:''})
        fieldList.push({type:'int',value:'remindNum',text:'短信催缴次数',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>